package com.wave.wavesystem.business.controller;

import com.mybatisflex.core.paginate.Page;
import com.wave.wavesystem.business.pojo.dto.log.UserLoginLogQueryRequest;
import wave.common.pojo.enums.RStatusEnum;
 import wave.common.pojo.entity.Result;
import com.wave.wavesystem.common.util.Condition;
import com.wave.wavesystem.common.util.Func;
import com.wave.wavesystem.business.pojo.entity.UserLoginLogEntity;
import com.wave.wavesystem.business.service.UserLoginLogService;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

import java.util.List;

/**
 * @author 夕下风波
 * @date 2025-02-11
 * @description 用户登录日志 访问层
 */
@RestController
@RequestMapping("/userLoginLog")
@Tag(name = "用户登录日志接口")
public class UserLoginLogController {

    @Resource
    private UserLoginLogService userLoginLogService;

    /**
     * 新增
     *
     * @param userLoginLog 新增实体
     */
    @Operation(summary = "保存")
    @PostMapping("/save")
    public Result<UserLoginLogEntity> save(@RequestBody UserLoginLogEntity userLoginLog) {
        userLoginLogService.save(userLoginLog);
        return Result.data(userLoginLog);
    }

    /**
     * 删除/批量删除
     *
     * @param ids id集合
     */
    @Operation(summary = "删除")
    @PostMapping("/remove")
    public Result<Boolean> remove(String ids) {
        List<String> idList = Func.strToStringList(ids);
        return Result.status(userLoginLogService.removeByIds(idList), RStatusEnum.SUCCESS);
    }

    /**
     * 更新
     *
     * @param userLoginLog 更新内容
     */
    @Operation(summary = "更新")
    @PostMapping("/update")
    public Result<UserLoginLogEntity> update(@RequestBody UserLoginLogEntity userLoginLog) {
        userLoginLogService.updateById(userLoginLog);
        return Result.data(userLoginLogService.getById(userLoginLog.getId()), RStatusEnum.SUCCESS);
    }

    /**
     * 详情查询
     *
     * @param userLoginLog 查询条件
     */
    @Operation(summary = "详情")
    @GetMapping("/detail")
    public Result<UserLoginLogEntity> detail(UserLoginLogQueryRequest userLoginLog) {
        return Result.data(userLoginLogService.getById(userLoginLog.getId()));
    }

    /**
     * 列表查询
     *
     * @param userLoginLogQueryRequest 查询条件
     */
    @Operation(summary = "列表")
    @GetMapping("/list")
    public Result<List<UserLoginLogEntity>> list(@RequestParam UserLoginLogQueryRequest userLoginLogQueryRequest) {
        UserLoginLogEntity userLoginLog = new UserLoginLogEntity();
        Func.beanCopy(userLoginLogQueryRequest, userLoginLog);
        return Result.data(userLoginLogService.list(Condition.getQueryWrapper(userLoginLog)));
    }

    /**
     * 条件分页查询
     *
     * @param userLoginLogQueryRequest 查询条件
     */
    @Operation(summary = "分页")
    @GetMapping("/page")
    public Result<Page<UserLoginLogEntity>> page(UserLoginLogQueryRequest userLoginLogQueryRequest) {
        UserLoginLogEntity userLoginLog = new UserLoginLogEntity();
        Func.beanCopy(userLoginLogQueryRequest, userLoginLog);
        return Result.data(userLoginLogService.page(new Page<>(userLoginLogQueryRequest.getPageNum(), userLoginLogQueryRequest.getPageSize()),
                Condition.getQueryWrapper(userLoginLog)));
    }

}